<script setup lang="ts">
  import { onMounted, ref } from 'vue';

  import useUser from '@/hooks/user';
  import { EChartsOption } from 'echarts';
  import MapContainer from '@/components/MapContainer/index.vue';
  import ReECharts from '@/components/ReECharts/index.vue';
  import { waterQualityCategoryDistribution } from '@/api/riversManger/waterQualityManger';
  import { reactive } from 'vue';
  import {
    useStatesCategoryDistribution,
    useStatesPhDistribution,
    useStatesRelevance,
    useStatesTurbidityDistribution,
    useStatesWaterTemperatureChange,
  } from '@/hooks/useStatisDevice';
  import vCharts from '@/components/v-charts/v-charts.vue';

  const { logout } = useUser();
  const nowTime = ref<string>();

  const getTime = () => {
    const myDate = new Date();
    const myYear = myDate.getFullYear(); // 获取完整的年份(4位,1970-????)
    const myMonth = myDate.getMonth() + 1; // 获取当前月份(0-11,0代表1月)
    const myToday = myDate.getDate(); // 获取当前日(1-31)
    const myDay = myDate.getDay(); // 获取当前星期X(0-6,0代表星期天)
    const myHour = myDate.getHours(); // 获取当前小时数(0-23)
    const myMinute = myDate.getMinutes(); // 获取当前分钟数(0-59)
    const mySecond = myDate.getSeconds(); // 获取当前秒数(0-59)
    const week = [
      '星期日',
      '星期一',
      '星期二',
      '星期三',
      '星期四',
      '星期五',
      '星期六',
    ];
    function fillZero(str: number) {
      let realNum;
      if (str < 10) {
        realNum = `0${str}`;
      } else {
        realNum = str;
      }
      return realNum;
    }
    nowTime.value =
      `${myYear}年${fillZero(myMonth)}月${fillZero(myToday)}日` +
      `  ${fillZero(myHour)}:${fillZero(myMinute)}:${fillZero(mySecond)}  ${
        week[myDay]
      }  `;
  };
  // 大屏
  setInterval(getTime, 1000);

  const mapRight1Option = ref<EChartsOption>();
  const mapRef = ref<HTMLDivElement>();
  const layers = ref<any[]>([]);
  const lngLat = ref<{ lng?: number; lat?: number }>({});
  const legendData = ref<any[]>([]);
  const indicatorData = ref<any[]>([]);
  const valueData = ref<any[]>([]);
  const a = ref<boolean>(false);
  const mapClick = (params: any) => {
    layers.value = params.data;
    lngLat.value.lng = params.lng;
    lngLat.value.lat = params.lat;
    legendData.value = layers.value.map((item) => item.name);
    indicatorData.value = layers.value.map((item) => ({
      name: item.name,
      min: item.minValue,
      max: item.maxValue,
    }));
    valueData.value = layers.value.map((item) => item.value);

    mapRight1Option.value = {
      legend: {
        // data: [`经度：${lngLat.value.lng}, 纬度度：${lngLat.value.lat}`],

        textStyle: {
          color: '#165DFF',
        },
      },
      radar: {
        // shape: 'circle',
        indicator: indicatorData.value,
      },

      series: [
        {
          type: 'radar',
          label: {
            show: true,
          },
          data: [
            {
              value: valueData.value,
              // name: `经度：${lngLat.value.lng}, 纬度度：${lngLat.value.lat}`,
            },
          ],
        },
      ],
    };
    a.value = true;
    console.log(params, legendData.value, indicatorData.value, valueData.value);
  };
  const { options: mapRight2Option } = useStatesRelevance();

  const { options: mapRight3Option } = useStatesTurbidityDistribution();

  // const mapRight2Option = ref<EChartsOption>({
  //   tooltip: {
  //     trigger: 'axis',
  //   },
  //   legend: {
  //     data: ['水温(℃)', '溶解氧(mg/L)'],
  //     textStyle: {
  //       color: '#165DFF',
  //     },
  //   },
  //   grid: {
  //     left: '3%',
  //     right: '4%',
  //     bottom: '3%',
  //     containLabel: true,
  //   },
  //   toolbox: {
  //     feature: {
  //       saveAsImage: {},
  //     },
  //   },
  //   xAxis: {
  //     type: 'category',
  //     boundaryGap: false,
  //     data: [
  //       '2024/4/22 16:00',
  //       '2024/4/22 12:00',
  //       '2024/4/22 16:00',
  //       '2024/4/22 16:00',
  //     ], // 填入你的监测时间数据
  //   },
  //   yAxis: {
  //     type: 'value',
  //   },
  //   series: [
  //     {
  //       name: '水温(℃)',
  //       type: 'line',
  //       data: [22, 21.9, 21.6, 24.5], // 填入对应的水温数据
  //     },
  //     {
  //       name: '溶解氧(mg/L)',
  //       type: 'line',
  //       data: [7.99, 8.35, 7.85, 9.23], // 填入对应的溶解氧数据
  //     },
  //   ],
  // });
  // const mapRight3Option = ref<EChartsOption>({
  //   xAxis: {
  //     type: 'value',
  //     name: '氨氮',
  //     scale: true,
  //   },
  //   yAxis: {
  //     type: 'value',
  //     name: '总磷',
  //     scale: true,
  //   },
  //   series: [
  //     {
  //       name: '氨氮与总磷',
  //       type: 'scatter',
  //       data: [
  //         [0.067, 0.21],
  //         [0.133, 0.38],
  //         [0.335, 0.91],
  //         [0.362, 1.04],
  //         [0.393, 1.21],
  //       ], // 这里应该填入对应的氨氮和总磷数据
  //     },
  //   ],
  // });

  const { options: mapLeft1Option } = useStatesCategoryDistribution();

  const { options: mapLeft2Option } = useStatesWaterTemperatureChange();

  const { options: mapLeft3Option } = useStatesPhDistribution();
</script>

<template>
  <div class="container">
    <div class="content-body">
      <div class="header public-bg">
        <div class="header-left">
          <span>无人机高光谱河流数据可视化平台</span>
        </div>
        <div class="header-right">
          <a-button
            v-if="$route.path.includes('home/index')"
            type="primary"
            style="margin-right: 20px; pointer-events: auto"
            @click="logout()"
            >退出登录</a-button
          >
          <span id="time">{{ nowTime }}</span>
        </div>
      </div>
      <MapContainer ref="mapRef" class="map-container" @mapClick="mapClick" />
      <div class="content" style="">
        <div class="content-con">
          <div class="left-body">
            <div class="left-top public-bg">
              <div class="public-title">福建省分类水质等级数量</div>
              <vCharts class="title-nav" type="bar" :options="mapLeft1Option" />
              <!-- <ReECharts
                class="title-nav"
                ref="mapLeft1Ref"
                :option="mapLeft1Option"
                width="100%"
                height="100%"
              /> -->
            </div>
            <div class="left-con public-bg">
              <div class="public-title">水温变化</div>
              <vCharts
                class="title-nav"
                type="line"
                :options="mapLeft2Option"
              />

              <!-- <ReECharts
                class="title-nav"
                :option="mapLeft2Option"
                width="100%"
                height="100%"
              /> -->
            </div>
            <div class="left-bottom public-bg">
              <div class="public-title">各省流域pH值</div>
              <vCharts
                class="title-nav"
                type="heatmap"
                :options="mapLeft3Option"
              />
              <!-- <ReECharts
                class="title-nav"
                :option="mapLeft3Option"
                width="100%"
                height="100%"
              /> -->
            </div>
          </div>

          <div class="right-body">
            <div class="right-top public-bg">
              <div class="public-title">高光谱数据</div>
              <vCharts
                class="title-nav"
                type="bar"
                :options="mapRight1Option"
              />
              <!-- <ReECharts
                v-if="a"
                class="title-nav"
                :option="mapRight1Option"
                width="100%"
                height="100%"
              /> -->
            </div>
            <div class="right-con public-bg">
              <div class="public-title">断面水质数据</div>
              <vCharts
                class="title-nav"
                type="bar"
                :options="mapRight2Option"
              />
              <!-- <ReECharts
                class="title-nav"
                :option="mapRight2Option"
                width="100%"
                height="100%"
              /> -->
            </div>
            <div class="right-bottom public-bg">
              <div class="public-title">氨氮与总磷的关系</div>
              <vCharts
                class="title-nav"
                type="bar"
                :options="mapRight3Option"
              />
              <!-- <ReECharts
                class="title-nav"
                :option="mapRight3Option"
                width="100%"
                height="100%"
              /> -->
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
  .dropdown-title {
    color: #fff;
  }
  .public-bg {
    background-color: rgba(89, 89, 89, 0.2);
    backdrop-filter: blur(3.5px);
    -webkit-backdrop-filter: blur(3.5px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: rgba(14, 14, 14, 0.19) 0px 6px 15px 0px;
    -webkit-box-shadow: rgba(14, 14, 14, 0.19) 0px 6px 15px 0px;
    border-radius: 15px;
    -webkit-border-radius: 15px;
    color: rgba(128, 128, 128, 0.8);
  }
  .public-bg /deep/ .myChart {
    width: 100%;
    height: calc(~'100% - 30px');
  }

  .public-title {
    position: relative;
    top: 0;
    left: 5px;
    width: calc(100% - 20px);
    height: 30px;
    padding-left: 16px;
    font-size: 13px;
    line-height: 30px;
    color: white;
  }

  .public-title::before {
    position: absolute;
    top: 5px;
    left: 5px;
    width: 4px;
    height: 20px;
    content: '';
    background: #2997e4;
    border-radius: 2px;
  }

  .content-body {
    position: absolute;
    width: 100%;
    height: 100%;
  }

  .header {
    position: relative;
    display: flex;
    margin-top: 10px;
    width: 100%;
    height: 70px;
    justify-content: space-between;
    z-index: 1;
    pointer-events: none;
    /*    border: 1px solid red; */
  }
  .header .header-body {
    float: left;
    width: 65%;
    height: 100%;
    padding: 30px;
  }

  .header .header-left {
    line-height: 70px;
    width: 412px;
  }

  .header .header-left span {
    padding: 0 20px;
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    constter-spacing: 2px;
  }

  .header .header-right {
    float: right;
    padding-right: 10px;
    line-height: 70px;
  }

  .header .header-right span {
    color: #fff;
  }

  .content {
    position: absolute;
    width: 100%;
    height: calc(100% - 70px);
    pointer-events: none;
  }

  .content .content-con {
    height: 100%;
    padding-top: 20px;
  }

  .content .content-con .left-body {
    position: relative;
    float: left;
    width: 24%;
    height: 100%;
    z-index: 1;
  }

  .left-body .left-top {
    width: 100%;
    height: 27%;
  }

  .left-body .left-top .top-body {
    width: 100%;
    height: calc(100% - 30px);
  }

  .left-body .left-top .top-body .top-left {
    float: left;
    width: 50%;
    height: 100%;
  }

  .top-left-title {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    padding: 30px;
  }

  .top-left-title h6 {
    color: #bad0e2;
  }

  .top-left-title span {
    display: inline-block;
    margin-top: 30px;
    color: #2aa4f1;

    /*    height: 80px;
    line-height: 80px; */
  }

  .top-left-title span b {
    font-size: 30px;
    constter-spacing: 5px;
  }

  .top-left-title img {
    width: 80%;
  }

  .left-body .left-top .top-body .top-right {
    float: left;
    width: 50%;
    height: 100%;
  }

  .left-body .left-con {
    width: 100%;
    height: 38%;
    margin-top: 1.6%;
  }

  .left-body .left-bottom {
    width: 100%;
    height: 32%;
    margin-top: 1.6%;
  }

  .center-body {
    margin: 0 0.3%;

    /* border: 1px solid red; */
  }

  .map-container {
    position: absolute;
    left: 0;
    top: 0;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
  }
  .map-container /deep/ .amap-ui-control-theme-layer-switcher {
    z-index: 99;
    background: #c2c9cc;
    border-radius: 10px;
  }

  .right-body {
    position: relative;
    float: right;
    width: 20%;
    z-index: 1;
    height: 100%;
    margin: 0 0.3%;
  }

  .right-body .right-top {
    width: 100%;
    height: 32%;
  }
  .right-body .right-top .maps {
    width: 100%;
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: space-around;
  }

  .title-nav {
    pointer-events: auto;
  }
  .title-nav .top5-ul {
    width: calc(100% - 20px);
    height: calc(100% - 30px);
    padding: 10px;
  }

  .title-nav .top5-ul ul {
    width: 100%;
    height: 100%;
  }

  .title-nav .top5-ul ul,
  li {
    list-style: none;
  }

  .title-nav .top5-ul ul > li {
    justify-content: center;
    width: 100%;
    height: 20%;
    line-height: 68px;
    color: #fff;
  }

  .title-nav .top5-ul ul li span {
    margin-left: 3%;
    font-size: 14px;
  }

  .title-nav .top5-ul ul li span:nth-child(1) {
    /* width: 10%; */

    /* #20a8fe
            #EB6841
            #3FB8AF
            #FE4365
            #FC9D9A */
    display: inline-block;
    font-size: 20px;
    font-style: oblique;
    color: #eb6841;
    text-align: center;
  }

  .title-nav .top5-ul ul li span:nth-child(2) {
    display: inline-block;
    width: 10%;
    height: 30px;
    line-height: 30px;
    color: #fff;
    text-align: center;

    /*    height: 100%; */

    /* line-height: 100%; */
    vertical-align: center;
    border-radius: 5px;
  }

  .title-nav .top5-ul ul li:nth-child(1) span:nth-child(2),
  .title-nav .top5-ul ul li:nth-child(2) span:nth-child(2),
  .title-nav .top5-ul ul li:nth-child(3) span:nth-child(2) {
    background: #d89346;
  }

  .title-nav .top5-ul ul li:nth-child(4) span:nth-child(2),
  .title-nav .top5-ul ul li:nth-child(5) span:nth-child(2) {
    background: #1db5ea;
  }

  .title-nav .top5-ul ul li span:nth-child(3) {
    /* width: 15%; */
    display: inline-block;
    text-align: center;
  }

  .title-nav .top5-ul ul li span:nth-child(4) {
    /* width: 15%; */
    display: inline-block;
    text-align: center;
  }

  .title-nav .top5-ul ul li span:nth-child(5) {
    /* width: 20%; */
    display: inline-block;
    text-align: center;
  }

  .title-nav .top5-ul ul li span:nth-child(6) {
    display: inline-block;
    text-align: center;
  }

  .right-body .right-con {
    width: 100%;
    height: 25%;
    margin-top: 2%;
  }

  .right-body .right-bottom {
    width: 100%;
    height: 39%;
    margin-top: 2%;
  }
  /deep/ .amap-logo,
  /deep/ .amap-copyright {
    display: none;
  }
</style>
